<template>
  <div>
    <div class="back-wrap"></div>
    <div class="task-wrap">
      <div class="title">任务</div>
      <div class="myLive">
        <div class="property">
          <div class="name">我的元宝</div>
          <div class="data" v-if="adUserData">
            {{ adUserData.coin | formatFront
            }}<span>{{ adUserData.coin | formatAfter }}</span>
          </div>
          <div class="dayproperty">
            昨日<span v-if="adUserData">{{
              adUserData.coinNum ? "+" + adUserData.coinNum : "0"
            }}</span>
          </div>
        </div>
        <div class="property">
          <div class="name">我的金豆</div>
          <div class="data" v-if="adUserData">
            {{ adUserData.otayonii | formatFront
            }}<span>{{ adUserData.otayonii | formatAfter }}</span>
          </div>
          <div class="dayproperty">
            今日<span v-if="adUserData">{{
              adUserData.otayoniiNum ? "+" + adUserData.otayoniiNum : "0"
            }}</span>
          </div>
        </div>
      </div>
      <div class="cell-group-wrap">
        <div class="cell-title">元宝任务</div>
        <div class="cell" v-for="(item,index) in cellGroup" :key="item.key">
          <svg-icon :iconClss="item.svg" className="cell-svg" />
          <div class="cell-content">
            <div class="cell-content-name">{{ item.name }}</div>
            <div class="cell-content-lable">{{ item.lable }}</div>
          </div>
          <div class="button-a" @click="clickCoin(index)">去完成</div>
        </div>
      </div>
      <div class="cell-group-wrap">
        <div class="cell-title">金豆任务</div>
        <div class="cell" v-for="(item, index) in cellGroup2" :key="item.key">
          <svg-icon :iconClss="item.svg" className="cell-svg" />
          <div class="cell-content">
            <div class="cell-content-name">{{ item.name }}</div>
            <div class="cell-content-lable">{{ item.lable }}</div>
          </div>
          <div class="button-a" @click="clickOtayonii(index)">马上赚</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { adUserData } from "@/api/task";
import { toGame, toTaskList, showReward } from "@/utils/APPempower";
export default {
  components: {
    svgIcon: (resolve) => require(["./svg"], resolve),
  },
  data() {
    return {
      adUserData: "",
      cellGroup: [
        {
          svg: "icon_task4",
          name: "观看首页视频90s",
          lable: "1分钟领奖",
        },
        {
          svg: "icon_task5",
          name: "观看激励视频3次",
          lable: "1分钟领奖",
        },
      ],
      cellGroup2: [
        {
          svg: "icon_task6",
          name: "精品下载",
          lable: "1分钟领奖",
        },
        {
          svg: "icon_task7",
          name: "游戏试玩",
          lable: "1分钟领奖",
        },
      ],
    };
  },
  filters: {
    formatFront(text) {
      return text.substring(0, text.indexOf("."));
    },
    formatAfter(text) {
      return text.substr(text.lastIndexOf("."));
    },
  },
  created() {
    adUserData({}).then((res) => {
      this.adUserData = res.data.resultData[0];
      console.log(this.adUserData);
    });
  },
  async mounted() {
    //安卓获取相册回调方法
    window["hideReward"] = () => {
      alert('调用了我hideReward方法')
    };
  },
  methods: {
    clickPage(name) {
      this.$router.push(name);
    },
    clickOtayonii(key) {
      switch (key) {
        case 0:
          toTaskList();
          break;
        default:
          toGame();
          break;
      }
    },
    clickCoin(key) {
      switch (key) {
        case 0:
          break;
        default:
          console.log('---')
          showReward();
          break;
      }
    },
  },
};
</script>
<style lang="less" scoped>
.back-wrap {
  position: absolute;
  overflow: hidden;
  height: 139px;
  top: 0;
  width: 100%;
  &:after {
    position: absolute;
    left: -25%;
    right: 0;
    content: "";
    width: 150%;
    height: 139px;
    position: absolute;
    top: 0;
    border-radius: 0 0 100% 100%;
    background: #333333;
  }
}
.task-wrap {
  position: relative;
  z-index: 1;
  padding: 0 18px;
  .title {
    padding: 54px 0 25px 0;
    text-align: center;
    font-size: 18px;
    line-height: 25px;
    color: #ffffff;
    position: relative;
    z-index: 1;
  }
  .myLive {
    padding: 10px 0 20px 0;
    display: flex;
    justify-content: space-between;
    background: #ffffff;
    box-shadow: 0px 0px 30px 0px rgba(0, 0, 0, 0.06);
    border-radius: 11px;
    .property {
      flex: 1;
      .name {
        padding-left: 16px;
        font-size: 12px;
        font-weight: 400;
        color: #333333;
        line-height: 17px;
      }
      .data {
        padding-top: 9px;
        height: 27px;
        font-size: 22px;
        text-align: center;
        font-weight: 600;
        color: #333333;
        line-height: 30px;
        span {
          font-size: 16px;
        }
      }
      .dayproperty {
        padding-top: 5px;
        text-align: center;
        height: 17px;
        font-size: 12px;
        font-weight: 400;
        color: #333333;
        line-height: 17px;
        span {
          margin-top: 5px;
          color: #f34a38;
        }
      }
      &:first-child {
        position: relative;
        &:after {
          position: absolute;
          content: "";
          top: 34px;
          right: 0;
          width: 1px;
          height: 17px;
          background: #f1f1f1;
          border-radius: 1px;
        }
      }
    }
  }
  .cell-group-wrap {
    margin-top: 13px;
    border-radius: 2px;
    padding: 0 12px;
    box-shadow: 0px 0px 30px 0px rgba(0, 0, 0, 0.1);
    .cell-title {
      position: relative;
      padding: 10px 0 6px 0;
      font-size: 14px;
      font-weight: 600;
      color: #333333;
      line-height: 14px;
    }
    .cell {
      position: relative;
      height: 60px;
      border-bottom: 1px solid #f1f1f1;
      font-size: 0;
      &:last-child {
        border: none;
      }
      .cell-svg {
        display: block;
        display: inline-block;
        vertical-align: top;
        margin-top: 15px;
        width: 32px;
        height: 32px;
        padding: 1px;
        box-sizing: border-box;
        border-radius: 100%;
      }
      .cell-content {
        display: inline-block;
        margin: 17px 0 0 12px;
        vertical-align: top;
        .cell-content-name {
          height: 12px;
          font-size: 12px;
          font-weight: 400;
          color: #333333;
          line-height: 12px;
        }
        .cell-content-lable {
          margin-top: 5px;
          height: 12px;
          font-size: 11px;
          font-weight: 400;
          color: #999999;
          line-height: 12px;
        }
      }
      .button-a {
        position: absolute;
        right: 0;
        top: 16px;
        width: 60px;
        height: 28px;
        font-size: 12px;
        font-weight: 400;
        text-align: center;
        color: #ffffff;
        border-radius: 2px;
        display: flex;
        justify-content: center;
        align-items: center;
        background: #333333;
      }
    }
  }
}
</style>